using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid;
using DevExpress.Utils;

using MM.Entities;
using MM.Business;  

namespace MM
{
    public partial class frmTimPhieuCK_KetQua : Form
    {
        string _matau = "";
        string _nguoitao = "";
        string _sConn = "";

        // the delegate the subscribers must implement
        public delegate void ChonPhieuChuyenKho(object frmTimPhieuCK_KetQua, ChonPhieuCKEventArgs chonPCKevent);

        // an instance of the delegate
        public ChonPhieuChuyenKho chonPCK;

        public frmTimPhieuCK_KetQua(string sConn, List<PHIEU_CHUYEN_KHO> lstPCK)
        {
            InitializeComponent();
            _sConn = sConn;

            this.gridControl1.DataSource = lstPCK;
        }

        private void lnkSoPhieuNK_Click(object sender, EventArgs e)
        {
            ColumnView col = (ColumnView)this.gridControl1.FocusedView;
            string mapck = col.FocusedValue.ToString();

            ChonPhieuCKEventArgs pckevent = new ChonPhieuCKEventArgs(mapck);

            if (chonPCK != null)
            {
                chonPCK(this, pckevent);
            }

        }

        private void gridDSVT_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                int index = gridDSVT.FocusedRowHandle;
                if (index >= 0)
                {
                    string mapck = gridDSVT.GetFocusedRowCellValue("MaPhieuChuyenKho").ToString();

                    ChonPhieuCKEventArgs pckevent = new ChonPhieuCKEventArgs(mapck);

                    if (chonPCK != null)
                    {
                        chonPCK(this, pckevent);
                    }
                }
            }
        }
    }

    class ChonPhieuCKEventArgs : EventArgs
    {
        public string MaPhieuChuyenKho = "";

        public ChonPhieuCKEventArgs(string mapck)
        {
            MaPhieuChuyenKho = mapck;
        }
    }
}